<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function post(url, data, async = true, dataType, success) {
            var xhr = new XMLHttpRequest();
            if (typeof data == object) {
                var arr = [];
                for (var key in data) {
                    var val = data[key];
                    arr.push(key + "=" + val);
                }
                data = arr.join("&");
            }
            xhr.open("post", url, async);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.send(data);
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    console.log(1);
                    var result = xhr.responseText;
                    if (dataType.toLowerCase() == "json") {
                        result = JSON.parse(result);
                    }
                    if (success) {
                        success(result);
                    }
                }
            }
        }
        post("../day6/php/html/php/register.php", "user=a123451&pwd=a123451&phone=13455555554&email=1234451@qq.com", true, "json", function success(result) {
            console.log(result);
        })
    </script>
</body>

</html>